package com.sky.controller.user;

import com.sky.constant.RedisConstant;
import com.sky.pojo.Merchant;
import com.sky.result.Result;
import com.sky.service.user.MerchantService;
import com.sky.vo.ShopVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("userShopController")
@RequestMapping("/user/shop")
@Api(tags = "用户端店铺接口")
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/status")
    @ApiOperation("查询店铺状态")
    public Result<Integer> getShopStatus(){
        Integer status =(Integer) redisTemplate.opsForValue().get(RedisConstant.SHOP_STATUS_KEY);
        if(status==null){
            //考虑到第一次
            status=0;
        }
        return Result.success(status);
    }

    @Autowired
    private MerchantService merchantService;

    //  获取店铺电话
    @GetMapping("/getMerchantInfo")
    @ApiOperation("获取商家信息")
    public Result   getMerchantInfo(){
        //  获取唯一商家对象信息
        Merchant merchant = merchantService.getShopById(1L);
        String  shopName = merchant.getShopName();
        String  shopAddress = merchant.getShopAddress();
        String  shopTelephone = merchant.getShopTelephone();
        ShopVO build = ShopVO.builder().phone(shopTelephone).shopName(shopName).shopAddress(shopAddress).build();
        return  Result.success(build);
    }
}
